module toggle_pin(
    input        clk,
    input        rst_n,
    input        din,
    output  reg  dout
    );

reg    in_d0;
reg    in_d1;


always @ (posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        in_d0 <= 1'b1;
        in_d1 <= 1'b1;
    end
    else begin
        in_d0 <= din;
        in_d1 <= in_d0;
    end
end


always @ (posedge clk or negedge rst_n) begin
    if(!rst_n)
        dout <= 1'b1;
    else if(in_d0==0  &&  in_d1 == 1)
        dout <= ~dout;
    else
        dout <= dout;
end

endmodule
